package cn.template.serve_project.controller;

import cn.template.serve_project.dto.login.LoginAccountDTO;
import cn.template.serve_project.dto.login.LoginWXDTO;
import cn.template.serve_project.result.Result;
import cn.template.serve_project.service.impl.AdminServiceImpl;
import cn.template.serve_project.service.impl.UserServiceImpl;
import cn.template.serve_project.vo.login.LoginAdminVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 登录
 */
@RestController
@Valid
public class LoginController {

    @Resource
    private UserServiceImpl userService;

    @Resource
    private AdminServiceImpl adminService;

    /**
     * 微信登录
     * @param dto 参数对象
     * @return 登录信息
     */
    @PostMapping("/wx/login")
    public Result<?> wxLogin(@RequestBody LoginWXDTO dto){
        return Result.success(userService.login(dto));
    }

    /**
     * 账号登录(Admin)
     * @param dto 参数对象
     * @return 登录信息
     */
    @PostMapping("/account/login")
    public Result<LoginAdminVO> accountLogin(@Valid @RequestBody LoginAccountDTO dto){
        return Result.success(adminService.login(dto));
    }


}
